#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>

struct list
{
  struct list* next;
  struct list* prev;
  char name[20];
  int age;
  char sex;
};


void get_data(struct list* head)
{
  FILE* file = fopen("./1.txt","r");
  struct list* new_node;
  char name[20] = {0};
  int age;
  char sex;
  int ret;
  while((ret = fscanf(file,"%s %d %c\n",name,&age,&sex) )!= -1)
  {
    printf("ret = %d\n",ret);
    new_node = malloc(sizeof(struct list));
    new_node->next = head->next;
    head->next = new_node;
    new_node->age = age;
    strcpy(new_node->name,name);
    new_node->sex = sex;

    printf("%s %d %c\n",name,age,sex);
    sleep(1);
  }

  fclose(file);
}

int main(int agrc,char** argv)
{
  struct list* head;
  head = malloc(sizeof(struct list));
  head->next = head->prev = head;
  FILE* file = fopen("./1.txt","w+");
  fprintf(file,"%s %d %c\n","lisi",1,'x');
  fprintf(file,"%s %d %c\n","zhangsan",2,'x');
  fprintf(file,"%s %d %c\n","nisan",2,'x');
  fclose(file);
  get_data(head);
  free(head);
  return 0;
}
